function GetRequest() {
        var url = location.search; //获取url中"?"符后的字串
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            var strs = str.split("&");
            for(var i = 0; i < strs.length; i ++) {
                theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
            }
        }
        return theRequest;
    }
var Request = new Object();
Request = GetRequest();

function getUrlParams(){
    var url = location.search;
    var bagin = url.indexOf("&");
    var backurl = url.substring(bagin+11,url.length);
    return backurl;
}

//o家APP初始ios 注册
function setupWebViewJavascriptBridge(callback) {
    if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); }
    if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); }
    window.WVJBCallbacks = [callback];
    var WVJBIframe = document.createElement('iframe');
    WVJBIframe.style.display = 'none';
    WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__';
    document.documentElement.appendChild(WVJBIframe);
    setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0)
}
//ios调用
setupWebViewJavascriptBridge(function(bridge) {
    bridge.registerHandler('testJSFunction', function(data, responseCallback) {
        responseCallback('js执行过了');
    })
})

//判断是android还是IOS系统
function checkOS() {
    var ua = navigator.userAgent.toLowerCase();
    if (/iphone|ipad|ipod/.test(ua)) {
        return "IOS";
    } else if (/android/.test(ua)) {
        return "Android";
    }
}

function returnBack(){
    //调用原生的返回上一页方法
    if(checkOS()=="Android"){
        maojia.mjGoBack();
    } else{
        setupWebViewJavascriptBridge(function(bridge) {
            bridge.callHandler('mjGoBack', function(response) {
            })
        })
    }
}

var url = document.location.toString();
var arrUrl = url.split("//");
var start = arrUrl[1].indexOf("/");
var relUrl = arrUrl[1].substring(0,start);

function query(){
    var backurl = getUrlParams();
    console.log(backurl);
    $.ajax({
        url: "/payQ/query",
        type: 'POST',
        async:false,
        data: {
            paymentId: Request['paymentId']
        },
        dataType: 'text',
        contentType: "application/x-www-form-urlencoded",
        success: function (data) {
            data = data.toString().trim();
            console.log(data);

            if (data == '00000000') {
                if(checkOS()=="Android"){
                    maojia.paystate(false);
                } else {
                    setupWebViewJavascriptBridge(function(bridge) {
                        bridge.callHandler('paystate',{result:false}, function(response) {
                        })
                    });
                }
                console.log("失败");
                window.open(arrUrl[0] + "//" + relUrl + "/payment/payError?backurl="+backurl, "_self");
            } else{
                if(checkOS()=="Android"){
                    maojia.paystate(true);
                } else {
                    setupWebViewJavascriptBridge(function(bridge) {
                        bridge.callHandler('paystate',{result:true}, function(response) {
                        })
                    });
                }
                console.log("成功");
                window.open(arrUrl[0] + "//" + relUrl + "/payment/paySuccess?backurl="+backurl, "_self");
            }
        },
        error: function () {
            window.open(arrUrl[0] + "//" + relUrl + "/payment/payError?backurl="+backurl, "_self");
        }
    });
}

setTimeout(function(){query();},2000);




